package com.repair.miniApp.controller;

import com.repair.common.constant.Constants;
import com.repair.common.core.domain.AjaxResult;
import com.repair.miniApp.controller.request.LoginRequest;
import com.repair.miniApp.controller.request.RegisterRequest;
import com.repair.miniApp.domain.User;
import com.repair.miniApp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api/user")
public class UserController {


    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginRequest request) {
        AjaxResult ajax=AjaxResult.success();
        User user = userService.login(request.getAccount(), request.getPassword(), request.getRole());
        System.out.println(user);
        ajax.put(Constants.MINIAPPUSER, user);
        return ajax;
    }



    @PostMapping("/register")
    public boolean register(@RequestBody RegisterRequest request) {
        return userService.register(request.getName(),request.getAccount(), request.getPassword(), request.getRole(), request.getPhone());
    }
}
